home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Nov 3 98
- //
- // Description:
- // This is a helper script to perfrom the snapKey command
- // using the various options that have been set
- //
- // Input Arguments:
- // int action 0 - just execute the command
- // 1 - show the option box dialog
- // 2 - return the drag command
- //
- // Return Value:
- // None.
- //
-
- proc setOptionVars (int $forceFactorySettings)
- {
- keySetOptionBoxCommon( { "snapKey",
- "unknown",
- "setOptionVars",
- $forceFactorySettings,
- 1 } );
- // snapKey time or value?
- //
- if ($forceFactorySettings || !`optionVar -exists snapKeyTimeValue`) {
- optionVar -intValue snapKeyTimeValue 1;
- }
-
- // snapKey time multiple
- //
- if ($forceFactorySettings || !`optionVar -exists snapKeyTimeMultiple`) {
- optionVar -floatValue snapKeyTimeMultiple 1.0;
- }
-
- // snapKey value multiple
- //
- if ($forceFactorySettings || !`optionVar -exists snapKeyValueMultiple`) {
- optionVar -floatValue snapKeyValueMultiple 1.0;
- }
- }
-
- global proc snapKeySetup (string $parent, string $selectionConnection, int $forceFactorySettings)
- {
- // Retrieve the option settings
- //
- setOptionVars ($forceFactorySettings);
-
- setParent $parent;
-
- keySetOptionBoxCommon( { "snapKey", $selectionConnection, "setup", 1 } );
-
- // snap key time or value?
- //
- int $snapTimeValue = `optionVar -query snapKeyTimeValue`;
- radioButtonGrp -edit -select $snapTimeValue snapTimeValue;
-
- // snap time multiple
- //
- float $snapToTime = `optionVar -query snapKeyTimeMultiple`;
- floatFieldGrp -edit -value1 $snapToTime snapToTime;
-
- // snap value multiple
- //
- float $snapToValue = `optionVar -query snapKeyValueMultiple`;
- floatFieldGrp -edit -value1 $snapToValue snapToValue;
-
- // Now get all the dependent widgets in the right
- // enabled/disabled/collapsed/expanded state
- //
- snapKeyWidgetsEnable ($selectionConnection);
- }
-
- global proc snapKeyCallback( string $parent, int $doIt,
- string $selectionConnection,
- int $performAction, int $fromGraphEditor )
- {
- setParent $parent;
-
- keySetOptionBoxCommon( { "snapKey", $selectionConnection, "callback" } );
-
- // snap time or value?
- //
- optionVar -intValue snapKeyTimeValue `radioButtonGrp -q -sl snapTimeValue`;
-
- // time multiple
- //
- optionVar -floatValue snapKeyTimeMultiple
- `floatFieldGrp -q -value1 snapToTime`;
-
- // value multiple
- //
- optionVar -floatValue snapKeyValueMultiple
- `floatFieldGrp -q -value1 snapToValue`;
-
- if( $doIt ) {
- performSnapKeyArgList( 1, { (string) $performAction,
- $selectionConnection, $fromGraphEditor } );
- string $tmpCmd = "performSnapKeyArgList 1 {";
- $tmpCmd += "\"" + $performAction + "\", ";
- $tmpCmd += "\"" + $selectionConnection + "\", ";
- $tmpCmd += "\"" + $fromGraphEditor + "\"}";
- addToRecentCommandQueue $tmpCmd "Snap Keys";
- }
- }
-
- global proc snapKeyDoSelectionChanged (string $selectionConnection)
- //
- // Description:
- // Since timeRange is irrelevant when there are
- // picked keyframes, collapse the timeRange
- // when there are. (This is hooked in to a SelectionChanged
- // trigger.)
- //
- {
- keySetOptionBoxCommon( { "snapKey", $selectionConnection, "selectionChanged" } );
- }
-
-
- global proc snapKeyWidgetsEnable (string $selectionConnection)
- //
- // Description:
- // These are the widgets that get enabled and
- // disabled based on the certain states. Put them
- // here so they're all in one place.
- //
- {
- keySetOptionBoxCommon( { "snapKey", $selectionConnection, "enable" } );
-
- // Time/Value multiple fields
- //
- $doTimeValue = `radioButtonGrp -q -select snapTimeValue`;
- floatFieldGrp -e -enable ( $doTimeValue != 2 ) snapToTime;
- floatFieldGrp -e -enable ( $doTimeValue != 1 ) snapToValue;
- }
-
- proc string snapKeyWidgets( string $tabLayout, string $selectionConnection, int $fromGraphEditor )
- {
- global int $gTextColumnWidthIndex;
-
- setParent $tabLayout;
-
- string $tabForm = `columnLayout -adjustableColumn true`;
-
- keySetOptionBoxCommon( { "snapKey", $selectionConnection, "widgets", $fromGraphEditor, 1 } );
-
- radioButtonGrp -nrb 3 -label "Snap"
- -label1 "Times"
- -label2 "Values"
- -label3 "Both"
- -sl 1
- -changeCommand ("snapKeyWidgetsEnable " + $selectionConnection)
- snapTimeValue;
-
- floatFieldGrp -label "Snap Times to Multiple of" -value1 1.0 snapToTime;
- floatFieldGrp -label "Snap Values to Multiple of" -value1 1.0 snapToValue;
-
- setParent ..;
-
- return $tabForm;
- }
-
- proc snapKeyOptions( string $selectionConnection, int $performAction,
- int $fromGraphEditor )
- {
- // Customisation options
- //
- // Name of the command for this option box (think of it as the base class)
- string $commandName = "snapKey";
- // Title for the option box window
- string $optionBoxTitle;
- string $applyTitle;
-
- $optionBoxTitle = "Snap Keys Options";
- $applyTitle = "Snap keys";
-
- // Build the option box "methods"
- //
- string $callback = ($commandName + "Callback");
- string $setup = ($commandName + "Setup");
-
- // Build the window, with a tab layout
- //
- string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`;
- setUITemplate -pushTemplate DefaultTemplate;
-
- // Make the form invisible while we create the widgets in the window
- //
- formLayout -e -vis false $widgetList[1];
-
- // Attach the widgets. No tab layout needed.
- //
- snapKeyWidgets $widgetList[2] $selectionConnection $fromGraphEditor;
-
- // Attach the standard buttons
- //
- string $buttonList[] = `addStandardButtons $commandName $applyTitle
- $widgetList[1] $widgetList[2] "noOptions"`;
-
- // attach commands to the standard buttons
- //
- // Save
- //
- button -e -c ($callback + " " + $widgetList[0] + " false \"\" " +
- $performAction + " " + $fromGraphEditor
- + "; hideOptionBox()") $buttonList[3];
-
- // Close
- //
- button -edit -command hideOptionBox $buttonList[2];
-
- // Reset
- //
- button -edit -command ($setup + " " + $widgetList[0] + " " + $selectionConnection + " true") $buttonList[1];
-
- // DoIt
- //
- button -edit -command ($callback + " " + $widgetList[0] + " true \"" +
- $selectionConnection + "\" " +
- $performAction + " " + $fromGraphEditor)
- $buttonList[0];
-
- // Make the form layout visible so we can see what we built, and
- // reset the template
- //
- formLayout -e -vis true $widgetList[1];
- setUITemplate -popTemplate;
-
- // Customize the 'Help' menu item text.
- // This is called from 3 different places so look at the selection
- // connection to try to figure out which one.
- //
- if (match ("graphEditor", $selectionConnection) != "") {
- setOptionBoxHelpTag( "GraphSnap" );
- } else if (match ("dopeSheet", $selectionConnection) != "") {
- setOptionBoxHelpTag( "DopeSnap" );
- } else {
- setOptionBoxHelpTag( "KeysSnapKeys" );
- }
-
- // Call the setup "method" to fill in the current settings
- //
- eval (($setup + " " + $widgetList[0] + " " + $selectionConnection + " false"));
- showOptionBox();
- showWindow $widgetList[0];
-
- if( $fromGraphEditor ) {
- snapKeyDoSelectionChanged($selectionConnection);
- scriptJob -protected -event "SelectionChanged"
- ("snapKeyDoSelectionChanged " + $selectionConnection + "; snapKeyWidgetsEnable " + $selectionConnection + ";")
- -parent $widgetList[2];
- }
- }
-
-
- proc string assembleCmd( string $selectionConnection,
- string $options,
- string $doSelectNotSnap,
- int $fromGraphEditor )
- {
- int $snapTimeValue = `optionVar -q snapKeyTimeValue`;
- int $snapTime = $snapTimeValue != 2;
- int $snapValue = $snapTimeValue != 1;
-
- // doSnapKeyArgList takes a string array
- //
- $cmd = "doSnapKeyArgList 1 { " +
- "\"" + `optionVar -q snapKeyAllAnimCurves` + "\"" +
- ",\"" + `optionVar -q snapKeyHierarchy` + "\"" +
- ",\"" + `optionVar -q snapKeyUseChannelBox` + "\"" +
- ",\"" + `optionVar -q snapKeyDriven` + "\"" +
- ",\"" + `optionVar -q snapKeyControlPoints` + "\"" +
- ",\"" + `optionVar -q snapKeyShapes` + "\"" +
- ",\"" + `optionVar -q snapKeyWhichRange` + "\"" +
- ",\"" + `optionVar -q snapKeyRange` + "\"" +
- ",\"" + $snapTime + "\"" +
- ",\"" + $snapValue + "\"" +
- ",\"" + `optionVar -q snapKeyTimeMultiple` + "\"" +
- ",\"" + `optionVar -q snapKeyValueMultiple` + "\"" +
- ",\"" + $doSelectNotSnap + "\"" +
- ",\"" + $selectionConnection + "\"" +
- ",\"" + $options + "\"" +
- ",\"" + $fromGraphEditor + "\"" +
- " };";
-
- return $cmd;
- }
-
- // $version == 1
- // [0] $action 0 - do the command
- // 1 - show the option box
- // 2 - return the drag command
- // 3 - do the command (bufferCurve vers.)
- // 4 - show the option box (bufferCurve vers.)
- // 5 - return the drag command (bufferCurve vers.)
- // 6 - do the "selectKey -unsnappedKeys" command
- // associated with the snapKey option settings
- // 7 - return the "selectKey -unsnappedKeys" cmd
- // associated with the snapKey option
- // settings
- // [1] $selectionConnection name of selection connection to use
- // [2] $fromGraphEditor true if called from GraphEditor/DopeSheet
- //
- global proc string performSnapKeyArgList( int $version, string $args[] )
- {
- int $action = $args[0];
- string $selectionConnection = $args[1];
- int $fromGraphEditor = $args[2];
-
- string $cmd = "";
-
- switch( $action ) {
- // Snap Key From Edit->Keys menu
- //
- case 0:
- setOptionVars( false );
- $cmd = assembleCmd ($selectionConnection, "noOptions", 0,
- $fromGraphEditor);
- eval( $cmd );
- break;
- case 1:
- snapKeyOptions( $selectionConnection, 0, $fromGraphEditor );
- break;
- case 2:
- setOptionVars( false );
- $cmd = assembleCmd ($selectionConnection, "noOptions", 0,
- $fromGraphEditor);
- break;
- // Snap Key From GE/DS Edit menu
- //
- case 3:
- setOptionVars( false );
- $cmd = assembleCmd ($selectionConnection, "bufferCurve", 0,
- $fromGraphEditor);
- eval( $cmd );
- break;
- case 4:
- snapKeyOptions( $selectionConnection, 3, $fromGraphEditor );
- break;
- case 5:
- setOptionVars( false );
- $cmd = assembleCmd ($selectionConnection, "bufferCurve", 0,
- $fromGraphEditor);
- break;
- // Select Unsnapped from GE/DS menu uses the optionVars
- // from snapKey.
- //
- case 6:
- setOptionVars( false );
- $cmd = assembleCmd ($selectionConnection, "bufferCurve", 1,
- $fromGraphEditor);
- eval( $cmd );
- break;
- case 7:
- setOptionVars( false );
- $cmd = assembleCmd ($selectionConnection, "bufferCurve", 1,
- $fromGraphEditor);
- break;
- }
-
- return ($cmd);
- }
-